package com.base.im.server.netty.echo;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class EchoServerHandler extends ChannelInboundHandlerAdapter{

	public void channelRead(ChannelHandlerContext ctx, Object msg) {  
		
		
		
        System.out.println("服务端收到 :" + msg); 
        
        Channel channel = ctx.channel();
        EchoSession.setSession(100, channel);
        
//        channel.writeAndFlush(msg);
//        ctx.write(msg);//写回数据，  
    }   
    public void channelReadComplete(ChannelHandlerContext ctx) { 
    	
    	ctx.flush();
//        ctx.writeAndFlush(Unpooled.EMPTY_BUFFER); //flush掉所有写回的数据  
//        .addListener(ChannelFutureListener.CLOSE); //当flush完成后关闭channel  
    }   
    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause) {   
        cause.printStackTrace();//捕捉异常信息  
        ctx.close();//出现异常时关闭channel   
    }     
	
}
